<%-- 
    Document   : profile
    Created on : 7-gen-2012, 10.50.35
    Author     : Admin
--%>

<%@page errorPage="/pages/error.jsp" contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<!DOCTYPE html>

<f:view locale="#{languagesBean.locale}">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><h:outputText value="#{lang.profileTitle}" /></title>
        </head>
        <body>
            <jsp:include page="/pages/header.jsp"/>
            
            <h:panelGroup id="backLink" layout="block" style="width:80%; margin-left:auto; margin-right:auto; background-color:white; color:blue; font-size:20px;">
                <a4j:form>
                    <a4j:commandLink id="docHome" value="HomePage" action="doctor" rendered="#{user.doctor}" style="text-align:center"/>
                    <a4j:commandLink id="uslHome" value="HomePage" action="usl" rendered="#{user.USL}" style="text-align:center"/>
                </a4j:form>
            </h:panelGroup>
            
            <rich:tabPanel style="margin-left:auto; margin-right:auto;" width="80%" headerAlignment="right" >
                
                <rich:tab id="profile" label="#{lang.profileTabPat}" action="#{patient.retrievePatient}">
                    <rich:panel id="mainProfile" header="#{patient.username}">
                        <%-- Il settaggio del paziente e del callerId e' avvenuto prima della chiamata a profile.jsp --%>
                        <a4j:form id="editPatient">
                            
                            <p>
                                <h:outputText value="#{lang.doctorRegName} " />                                
                                <h:inputText value="#{patient.name}" disabled="#{patient.editable}"/>
                                
                                <h:outputText value="#{lang.doctorRegSurname} " />
                                <h:inputText value="#{patient.surname}" disabled="#{patient.editable}"/>                                
                                
                                <h:outputText value="#{lang.doctorRegGender} " />
                                <h:selectOneRadio id="gender" value="#{patient.gender}" disabled="#{patient.editable}">
                                    <f:selectItem id="M" itemLabel="M" itemValue="M" />
                                    <f:selectItem id="F" itemLabel="F" itemValue="F" />
                                </h:selectOneRadio>
                            </p>
                            
                            <h:outputText value="#{lang.doctorRegBirthDate} " />
                            <rich:calendar id="date" value="#{patient.calendarBirthdate}" disabled="#{patient.editable}"/>
                            
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegBirthPlace} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.birthplace}" disabled="#{patient.editable}"/>
                            
                            <h:outputText value="#{lang.doctorRegAddress} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.address}" disabled="#{patient.editable}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegCAP} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.cap}" disabled="#{patient.editable}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegEmail} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.email}" disabled="#{patient.editable}" />
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegParentUsername} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.parentId}" disabled="#{patient.editable}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegCell} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.phone}" disabled="#{patient.editable}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegChiefTain} " style="font-weight:bold; font-size:10px;"/>
                            <h:inputText value="#{patient.chiefTainId}" disabled="#{patient.editable}"/>
                            <br>
                            
                            <h:outputText value="#{lang.doctorRegPictures} " style="font-weight:bold; font-size:10px;"/><BR>
                            <h:graphicImage value="#{patient.picture}" width="150" height="150"/>
                            <%-- Upload Picture --%>
                            <rich:simpleTogglePanel opened="false" value="Upload #{lang.doctorRegPictures}" width="50%">
                                <rich:fileUpload
                                    disabled="#{patient.editable}"
                                    fileUploadListener="#{patient.uploadListener}"
                                    maxFilesQuantity="1"
                                    immediateUpload="true"
                                    acceptedTypes="jpg, gif, png, bmp"
                                    />
                            </rich:simpleTogglePanel>
                            <br>
                            
                            <p>
                                <a4j:commandButton value="#{lang.profileEdit}" 
                                                   action="#{patient.toggleEditable()}"
                                                   reRender="mainProfile"
                                                   />
                                
                                <a4j:commandButton value="#{lang.profileSave}" 
                                                   action="#{patient.editPatient()}"
                                                   reRender="mainProfile"
                                                   />
                            </p>
                        </a4j:form>
                    </rich:panel>
                </rich:tab>
                
                <rich:tab id="map" label="GoogleMap" action="#{patient.retrieveCoords}">
                    <rich:gmap id="googlemap" lat="#{patient.latitude}" lng="#{patient.longitude}" zoom="14" mapType="G_NORMAL_MAP" gmapKey="#{user.googleKey}" style="margin-left:auto; margin-right:auto;"/>                       
                    <h:outputLink target="_blank" value="#{patient.wikiLink()}" style="margin-left:auto; margin-right:auto;">Wikipedia</h:outputLink>
                </rich:tab>
                
                <rich:tab id="hystory" label="#{lang.profileTabAnam}" action="#{patient.loadPastVisits()}">
                    <%-- Il settaggio del paziente e del callerId e' avvenuto prima della chiamata a profile.jsp --%>
                    <%-- Tabella visite passate (anamnesi)--%>
                    <a4j:form>
                        <rich:dataTable id="hystoryTable" value="#{patient.myVisits}" var="patVis" rows="20" width="100%">
                            
                            <f:facet name="header">
                                <h:outputText value="#{lang.profileTabAnam}" />
                            </f:facet>
                            
                            <rich:column sortBy="#{patVis.visit_id}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisId}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.visit_id}"/>
                            </rich:column>
                            
                            <rich:column sortBy="#{patVis.date}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisDate}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.date}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisMed}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.doctor_id}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisRep}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.report}"/>
                            </rich:column>
                            
                            <f:facet name="footer">
                                <rich:datascroller id="scroller"></rich:datascroller>
                            </f:facet>
                            
                        </rich:dataTable>
                    </a4j:form>
                </rich:tab>
                
                <rich:tab id="visits" label="#{lang.profileTabVis}" action="#{patient.loadMyFutureVisits()}">                    
                    <%-- Il settaggio del paziente e del callerId e' avvenuto prima della chiamata a profile.jsp --%>
                    <%-- Tabella visite future --%>
                    <a4j:form>
                        <rich:dataTable  id="visitsTable" value="#{patient.myVisits}" var="patVis" rows="20" width="100%">
                            
                            <f:facet name="header">
                                <h:outputText value="#{lang.profileTabVis}" />
                            </f:facet>
                            
                            <rich:column sortBy="#{patVis.visit_id}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisId}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.visit_id}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisUrg}"/>
                                </f:facet>
                                <h:graphicImage value="#{patVis.urgencyImg()}" width="50" height="50"/>
                            </rich:column>
                            
                            <rich:column sortBy="#{lang.profileVisDate}">
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisDate}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.date}"/>
                            </rich:column>
                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="#{lang.profileVisMed}"/>
                                </f:facet>
                                <h:outputText value="#{patVis.doctor_id}"/>
                            </rich:column>
                            
                            <f:facet name="footer">
                                <rich:datascroller id="scroller" ></rich:datascroller>
                            </f:facet>
                            
                        </rich:dataTable>
                    </a4j:form>
                    <%-- Aggiungi una visita --%>
                    
                    
                    <%-- Parametri per la visita --%>
                    
                    <f:setPropertyActionListener target="#{visit.patient_id}" value="#{patient.id}"/>
                    <f:setPropertyActionListener target="#{visit.doctor_id}" value="#{patient.refDoctorId}"/>
                    
                    <%-- Form per il referto--%>
                    <a4j:form id="addVisit" rendered="#{user.isDoctor()}">
                        
                        <p>
                            <h:inputTextarea id="report" label="#{lang.profileReport}" value="#{visit.report}" style="height:150; width:100%; "/>
                        </p>
                        <a4j:commandButton value="#{lang.profileComplete}"
                                           action="#{visit.addContingentVisit()}"
                                           reRender="addVisit"
                                           />
                    </a4j:form>
                </rich:tab>
            </rich:tabPanel>
            
        </body>
    </html>
</f:view>